package cn.zcj.studytest.config;


import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@EqualsAndHashCode(callSuper = true)
public class ZcjException extends RuntimeException{

    private Integer code;
    private String msg;

    public ZcjException() {
        this(400, "错误请求");
    }

    public ZcjException(String msg) {
        this(400, msg);
    }


    public ZcjException(Integer code, String msg) {
        super(msg);
        this.code = code;
        this.msg = msg;
    }

    public ZcjException(String message, String... params) {
        this();
        int paramIndex = 0;
        while (message.contains("{}") && paramIndex < params.length) {
            message = message.replaceFirst("\\{}", params[paramIndex]);
            paramIndex++;
        }
        this.msg = message;
    }

    public ZcjException(Integer code, String msg, Object... params) {
        super(msg);
        this.code = code;
        this.msg = params != null && params.length > 0 ? String.format(msg, params) : msg;
    }
}
